from rest_framework.generics import ListAPIView
from rest_framework.viewsets import ModelViewSet

from meiduo_admin.good.spec_option_serializers import SpecOptionsSerializer, SpecListSerializer
from meiduo_admin.my_paginate import MyPageNumberPagination
from goods.models import SpecificationOption, SPUSpecification


class SpecsOptionsViewSet(ModelViewSet):
    queryset = SpecificationOption.objects.all()
    pagination_class = MyPageNumberPagination
    serializer_class = SpecOptionsSerializer


class SpecListView(ListAPIView):
    serializer_class = SpecListSerializer
    def get_queryset(self):
        queryset = SPUSpecification.objects.all()
        for spec in queryset:
            spec.name += '%s-%s'%(spec.spu.name,spec.name)
        return queryset
